package com.controller;

import com.entity.LoginBean;
import com.entity.Result;

import com.entity.User;
import com.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@CrossOrigin
@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;

    @RequestMapping("/login")
    public Result login(@RequestBody LoginBean loginBean, HttpServletRequest request){
        try {
            String login=loginService.login(loginBean,request);

            if ("true".equals(login)){
                return new Result(true,"登录成功",login);
            }else {
                return new Result(false,"登录失败,请重新登录");
            }
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"登录失败，服务器故障");
        }
//        System.out.println(loginBean);

    }
}
